package com.achao.achaomq.entity;

import com.achao.achaomq.constants.CommonConstants;

import java.io.Serializable;

/**
 * 描述：通用API接口返回
 *
 * @Author：yangchao
 * @CreateDate：2023/2/4 20:02
 */
public class R<T> implements Serializable {
    private static final long serialVersionUID = -8840249062573943706L;
    /** 通用返回状态 */
    private int code;
    /** 通用返回信息 */
    private String msg;
    /** 通用返回数据 */
    private T data;

    public R() {}

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    private static <T> R<T> restResult(T data, int code, String msg) {
        R<T> musicResult = new R<>();
        musicResult.setCode(code);
        musicResult.setData(data);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public static <T> R<T> successResult(T data, String msg) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.SUCCESS);
        musicResult.setData(data);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public static <T> R<T> successResult(T data) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.SUCCESS);
        musicResult.setData(data);
        return musicResult;
    }

    public static <T> R<T> successResult(String msg) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.SUCCESS);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public static <T> R<T> failResult(String msg) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.FAIL);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public static <T> R<T> failResult(T data,String msg) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.FAIL);
        musicResult.setData(data);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public static <T> R<T> failResult(T data) {
        R<T> musicResult = new R<>();
        musicResult.setCode(CommonConstants.FAIL);
        musicResult.setData(data);
        return musicResult;
    }
    public static <T> R<T> failResult(String msg,Integer code) {
        R<T> musicResult = new R<>();
        musicResult.setCode(code);
        musicResult.setMsg(msg);
        return musicResult;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}